<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>后台登录</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/stylesheets/base.css">
    <script src="/layui/layui.js"></script>
    <script src="/javascripts/jquery.js"></script>
    <script src="/javascripts/ajax.js"></script>
    <style>
        .main{
            height: 100vh;
            width: 100vw;
            overflow: hidden;
            display: flex;
            align-items: center;
            justify-content: center;
            background: url("/images/login-bg.jpg") no-repeat center/cover;
        }
        .main .login-form{
            height: 30vh;
            width: 30vw;
            padding: 10px;
            background-color: rgba(255,255,255,.4);
            border-radius: 10px;
        }
        .main .login-form h3{
            height: 40px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="main">
        <div class="login-form">
            <h3>机蜂超市仓库管理系统</h3>
            <form class="layui-form">
                <div class="layui-form-item">
                    <label for="username" class="layui-form-label"><span class="red">*</span>用户名:</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" id="username" placeholder="请输入用户名" required lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="password" class="layui-form-label"><span class="red">*</span>密码:</label>
                    <div class="layui-input-block">
                        <input type="password" name="password" id="password" placeholder="请输入密码" required lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <button type="submit" lay-submit lay-filter="loginBtn" class="layui-btn">登录</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</body>
<script>
    $(function () {
        const form = layui.form;
        form.on("submit(loginBtn)",function (data) {
            ajax.post("/login",data.field).then(()=>{
                layer.msg("登录成功！",{icon:6})
                location.replace("/home")
            })
            // $.ajax({
            //     url:"/login",
            //     method:"post",
            //     data:data.field,
            //     success(res){
            //         if(res.code === 200){
            //             layer.msg("登录成功！",{icon:6})
            //             location.replace("/home")
            //         }else{
            //             layer.alert(res.msg,{icon:5})
            //         }
            //     },
            //     error(e){
            //         layer.alert("与服务器断开连接，请稍后再试...",{icon:5});
            //         console.log(e);
            //     }
            // })
            return false;
        })
    })
</script>
</html>
